package chris.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;

/**
 * RabbitmqComponentDefineConfig
 * 批量申明exchange、queue、binding的方式 和 组合申明exchange、queue、binding的方式
 *
 * @author nanxin.chen
 * @since 2017/7/5
 */
@Configuration
public class RabbitmqComponentDefineConfig {

    //批量申明exchange、queue、binding的方式
    @Bean
    public List<Exchange> exchanges() {
        return Arrays.asList(
                new DirectExchange("e2", false, true),
                new DirectExchange("e3", false, true)
        );
    }

    @Bean
    public List<Queue> queues() {
        return Arrays.asList(
                new Queue("q2", false, false, true),
                new Queue("q3", false, false, true)
        );
    }

    @Bean
    public List<Binding> bindings() {
        return Arrays.asList(
                new Binding("q2", Binding.DestinationType.QUEUE, "e2", "k2", null),
                new Binding("q3", Binding.DestinationType.QUEUE, "e3", "k3", null)
        );
    }


    //组合申明exchange、queue、binding的方式
    @Bean
    public List<Declarable> ds() {
        return Arrays.asList(
                new DirectExchange("e4", false, true),
                new Queue("q4", false, false, true),
                new Binding("q4", Binding.DestinationType.QUEUE, "e4", "k4", null)
        );
    }

}
